﻿#include "computer.h"
#include "syscfg.h"


bool compareComputer(const Computer &var1, const Computer &var2)
{
    if(var1.ip.compare(var2.ip) > 0)
    {
        return false;
    }
    return true;
}
Computer::Computer()
{
    this->id = -1;

   lastHeartBeatTime = QDateTime::currentDateTime().addDays(-2); //默认肯定过期了

   unReadALarmCount = 0;

   apps = "";
}

Computer:: Computer(QString &name, int fromSource, QString &ip, QString &comment, QString apps)
{
    this->id = -1;
    this->name = name;
    this->ip = ip;
    this->comment = comment;
    this->fromSource = fromSource;
    this->apps = apps;

    lastHeartBeatTime = QDateTime::currentDateTime().addDays(-2); //默认肯定过期了

    unReadALarmCount = 0;
}

void Computer::copyBasicInfo(Computer &computer)
{
    this->id = computer.id;
    this->name = computer.name;
    this->ip = computer.ip;
    this->comment = computer.comment;
    this->fromSource = computer.fromSource;
    this->apps = apps;
}

bool Computer::isOffLine(QDateTime heartBeatTime)
{
    return heartBeatTime.secsTo(QDateTime::currentDateTime()) > 2 + HEART_BEAT_INTERVAL_SECONDS;
}

bool Computer::isOffLine()
{
    return isOffLine(lastHeartBeatTime);
}

QString Computer::getOffLineState()
{
    if(isOffLine())
    {
        return "未连接";
    }
    else
    {
        return "连接中";
    }
}
